package com.software.cool.api.admin.v1.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * @author admin
 * @date 2019/5/25
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdminV1Result<T>{

	/** code=0 成功，1=失败，-1=未登录 **/
	private Integer code=1;
	private String msg;
	private Integer count;
	private T data;
	private Map<String,Object> otherData;

	/**
	 * 默认返回成功
	 * @param result 返回成功时的数据
	 * @return 返回对应成功的CommonReturnType实体, data字段通过参数指定
	 */
	public static <T> AdminV1Result success(T result){
		AdminV1Result<T> type = new AdminV1Result<>();
		type.setCode(0);
		type.setMsg("");
		type.setData(result);
		return type;
	}

	/**
	 * 默认返回成功
	 * @param result 返回成功时的数据
	 * @return 返回对应成功的CommonReturnType实体, data字段通过参数指定
	 */
	public static <T> AdminV1Result success(T result,Integer count){
		AdminV1Result<T> type = new AdminV1Result<>();
		type.setCode(0);
		type.setMsg("");
		type.setCount(count);
		type.setData(result);
		return type;
	}

	/**
	 * 默认返回成功， 不带任何数据
	 * @param <T>
	 * @return
	 */
	public static <T> AdminV1Result success(){
		return AdminV1Result.success(null);
	}

	
	public static AdminV1Result fail(String msg) {
		AdminV1Result type = new AdminV1Result();
		type.setCode(1);
		type.setMsg(msg);
		return type;
	}
}
